<?php
include '/var/www/html/new/d/common/header.html';
include '/var/www/html/new/d/common/left.html';

// 员工权限判定
if($_SESSION['dtype']==6){
	$qx_arr = explode(',', $_SESSION['qx']);
	if(!in_array('repayment', $qx_arr)) exit('很抱歉，您没有权限操作此页面');
}


$ac = $GLOBALS['_ac'];
$pw = $GLOBALS['_pw'];
$s  = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));


$fid = $_SESSION['sid'];// 
$aid = $_GET['aid']+0;// 供应商ID
$did = $_GET['did']+0;// 分销商ID
$mid = $aid;// 搜索分销商
$var['rule'] = 0;

if($aid==0 && $did==0) exit('非法访问');

if($aid==0){// 供应商查看分销商
	$fid = $did;
	$aid = $_SESSION['sid'];
	$mid = $did;
	$var['rule'] = 1;
}
if ($_GET['did']>0) {
    $parent_id = $_SESSION['sid'];
    $son_id    = intval($_GET['did']);
} elseif($_GET['aid']>0) {
    $parent_id = intval($aid);
    $son_id    = intval($_SESSION['sid']);
}

$sql_chk = "SELECT id FROM pft_member_relationship WHERE parent_id=$parent_id AND son_id=$son_id LIMIT 1";
$GLOBALS['le']->query($sql_chk);
if(!$GLOBALS['le']->fetch_assoc()) {
    echo <<<JS
<script>alert("供销关系未建立！！");history.go(-1);</script>
JS;
    exit;
}

$sql = "select dname,account from pft_member where id=$mid limit 1";
$GLOBALS['le']->query($sql);
if(!$GLOBALS['le']->fetch_assoc()) exit('非法访问');
$var['dname']   = $GLOBALS['le']->f('dname');
$var['account'] = $GLOBALS['le']->f('account');
$var['dtype']   = $_GET['dtype'];

// 账户余额
$resxml = $s->PFT_Member_Fund($_SESSION['sid'],0);
$simxml = simplexml_load_string($resxml);
$var['balance'] = $simxml->Rec->UUamoney/100;// 账户余额

// 供应商授信额度
$resxml1 = $s->PFT_Member_Fund($fid,1,$aid);
$simxml1 = simplexml_load_string($resxml1);
$var['credit1'] = (int)$simxml1->Rec->UUkmoney/100;// 可用额度
$resxml2 = $s->PFT_Member_Fund($fid,2,$aid);
$simxml2 = simplexml_load_string($resxml2);
$var['credit2'] = (int)$simxml2->Rec->UUbasecredit/100;// 授信额度
$var['credit3'] = $var['credit1'] + $var['credit2'];

// 开始时间
$var['beginDate'] = date('Y-m-d', time()-2592000);
$var['endDate']   = date('Y-m-d');

include '/var/www/html/new/d/tpl/new_tpl/credit_/credit.tpl';
include '/var/www/html/new/d/common/footer.html';